/* 
 *  File: Accomodation.java
 *  Author: Edson Pereira
 *  Version: 1.0
 *  Date: 02/10/2011
 *  
 *  Oracle Certified Master Java SE 6 Developer
 *  
 *  This class is part of Java Developer Assignment CX-310-252A_1
 */

package suncertify.domain;

/**
 * An Accommodation object is facade and a transfer object that represent
 * of record data of database.
 *
 * <p>Accommodation is composed by customer identify owner of rental this 
 * Accommodation, status of this record, {@link Hotel} information and 
 * {@link Room} information.</p>
 * 
 * <table>
 * <tr><td>
 * <h3> Accommodation Fields</h3>
 * </td></tr><tr><td>
 * <h4>Hotel Information</h4>
 * <td></td></tr><tr><td></td><td>
 * 1 - Hotel Name
 * </td></tr><tr><td></td><td>
 * 2 - Hotel City
 * <td></tr><tr><td>
 * <h4>Room Information</h4>
 * <td></td></tr><tr><td></td><td>
 * 3 - Room Size
 * </td></tr><tr><td><td>
 * 4 - Is Smoking Room
 * </td></tr><tr><td><td>
 * 5 - Room Price for rental
 * </td></tr><tr><td><td>
 * 6 - Date when this room will be available
 * <td></tr><tr><td>
 * <h4>Accommodation Information</h4>
 * <td></td></tr><tr><td></td><td>
 * 7 - Customer Identify number for rental Accommodation
 * </td></tr><tr><td><td>
 * 8 - Accommodation was deleted
 * </table>
 * 
 * @see Hotel
 * @see Room
 * @author Edson Pereira
 * @version 1.0
 */
public class Accommodation{

    private static final String SEPARATOR = "; ";
    
    /*
     * Indexes to map array of string in Accommodation fields
     */
    private static final int NAME_INDEX = 1;
    private static final int CITY_INDEX = 2;
    private static final int CAPACITY_INDEX = 3;
    private static final int SMOKING_INDEX = 4;
    private static final int PRICE_INDEX = 5;
    private static final int DATE_INDEX = 6;
    private static final int CUSTOMER_INDEX = 7;
    private static final int STATUS_INDEX = 8;
    
    /*
     *  Private members declaration
     */
    private int customer;
    private boolean status;
	private Hotel hotelInformation;
    private Room roomInformation;
    
    /**
     * Creates an instance of Accommodation with an array of {@code String} of
     * initial value
     * 
     * @param data An array of {@code String} with Accommodation fields
     */
    Accommodation(String[] data){
        customer = Integer.parseInt(data[CUSTOMER_INDEX]);
        hotelInformation = new Hotel(data[NAME_INDEX], data[CITY_INDEX]);
        roomInformation  = new Room(Integer.parseInt(data[CAPACITY_INDEX]),
        		                    Boolean.parseBoolean(data[SMOKING_INDEX]),
                                    Long.parseLong(data[PRICE_INDEX]),
                                    data[DATE_INDEX]);
    }
    
    /**
     * Gets customer number
     * 
     * @return An {@code int} that represents customer identifier
     */
    public int getCustomer(){
        return this.customer;
    }
    
    /**
     * Sets customer identifier for Accommodation
     * 
     * @param customer Customer identifier
     */
    public void setCustomer(int customer){
        this.customer = customer;
    }
    
    /**
     * Gets hotel name
     * 
     * @return {@code String} with hotel name
     */
    public String getName(){
        return hotelInformation.getName();
    }
    
    /**
     * Sets hotel name where Accommodation is located
     * 
     * @param name Hotel name
     */
    public void setName(String name){
        hotelInformation.setName(name);
    }
    
    /**
     * Gets city name
     * 
     * @return {@code String} with city name
     */
    public String getCity(){
        return hotelInformation.getCity();
    }
    
    /**
     * Sets city name of Accommodation
     * 
     * @param city City name
     */
    public void setCity(String city){
        hotelInformation.setCity(city);
    }
    
    /**
     * Gets Accommodation size
     * 
     * @return {@code int} value of Accommodation size
     */
    public int getCapacity(){
	    return roomInformation.getCapacity();
	}

    /**
     * Sets Accommodation size
     * 
     * @param capacity {@code int} value of Accommodation size
     */
	public void setCapacity(int capacity){
	    roomInformation.setCapacity(capacity);
	}

	/**
	 * Gets {@code String} that represents available date of rental
	 * Accommodation
	 * 
	 * @return A {@code String} representation of date in format yyyy-mm-dd
	 */
   	public String getDate(){
	    return roomInformation.getDate();
	}
    
   	/**
   	 * Sets data when Accommodation is available follow in standard 
   	 * yyyy-mm-dd
   	 * 
   	 * @param date When Accommodation will be available for rental
   	 */
	public void setDate(String date){
	    roomInformation.setDate(date);
	}
	
	/**
	 * Gets Accommodation status of smoking
	 * 
	 * @return {@code true} if Accommodation is smoking, false otherwise
	 */
	public boolean isSmoking(){
	    return roomInformation.isSmoking();
	}

	/**
	 * Sets Accommodation as smoking or not
	 * 
	 * @param smoking 
	 */
    public void setSmoking(boolean smoking){
	    roomInformation.setSmoking(smoking);
	}

    /**
     * Gets price of Accommodation
     * 
     * @return {@code long} Value of rental
     */
	public long getPrice(){
	    return roomInformation.getPrice();
	}
    
	/**
	 * Sets the price of rental Accommodation
	 * 
	 * @param price Value of rental
	 */
    public void setPrice(long price){
        roomInformation.setPrice(price);
    }
    
    /**
     * Returns a {@String} representation of the Accommodation class
     *
     * @return A {@String} representation of the Accommodation class
     */
    public String toString(){
        String accomodationString = "[ " + hotelInformation.toString() 
                                         + SEPARATOR
                                         + roomInformation.toString() 
                                         + SEPARATOR
                                         + customer + " ]";
        return accomodationString;
     }
     
     /**
      * Returns a hash code for this {@code Accommodation}. 
      * 
      * <p>The hash code will be the hash code of {@code String} 
      * representation of {@code Accommodation}
      * 
      * @return An {@code int} value
      */
     public int hashCode(){
        return this.toString().hashCode();
     }
     
     /**
      * Compares this Accommodation to the specified object. 
      * <p>The result is {@code true} if and only if the argument is not 
      * {@code null} and is a Accommodation object that represents the same 
      * sequence of characters as this object.
      *
      * @param compareAccomodation - the Accomodation to be compared
      * @return {@code true} if the Accommodation is equal, false otherwise
      */
     public boolean equals (Object compareAccomodation){
         if ((compareAccomodation == null)
        		 || (!(compareAccomodation instanceof Accommodation))){
             return false;
         }
         return this.toString().equals(compareAccomodation.toString());
    }
    
   /**
    * Converts Accommodation to an array of {@code String}, where {@code n} is 
    * a field of record
    * 
    * @return An array of {@code String} , where {@code n} is a field of record
    */
    public String[] asStringArray(){
        String[] result = {hotelInformation.getName(),
        		           hotelInformation.getCity(),
        		           String.valueOf(roomInformation.getCapacity()),
        		           String.valueOf(roomInformation.isSmoking()),
        		           String.valueOf(roomInformation.getPrice()), 
        		           String.valueOf(roomInformation.getDate()),
                           String.valueOf(getCustomer())};
        return result;
    }
}